#ifndef ANALYDATALOADED_H
#define ANALYDATALOADED_H
#include <QMutex>
#include <QtWidgets>
#include "tools/Reader.h"
#include "solar/beacon/Field.h"
#include "solar/trunk/NWidget.h"
#include <QMutexLocker>

class StickTData : public QObject, public QRunnable{

    Q_OBJECT

public:

    StickTData(QMap<QString, qint64> &_RdoMap_Integer_){
        RdoMap_Integer = &_RdoMap_Integer_;
    }

    void run(){
    st_mutex.lock();
    emit finish(false);
    QString StickData = Reader::g_clipb().c_str();
    int TotalLenght = StickData.size();
    int SingleStep = 5000;
    int AddCount = 0;
    int range = floor((double)TotalLenght / (double)SingleStep);
    if (TotalLenght < SingleStep) SingleStep = TotalLenght;
    QString RegTxt = ".{%1}+";
    QRegularExpressionMatchIterator Iter = QRegularExpression(RegTxt.arg(SingleStep)).globalMatch(StickData);
    while (Iter.hasNext())
    {
        if ((*RdoMap_Integer)[RPLKEY.UPD_THREAD_STATE] == NT::THREAD_TERMINATED) {
            IsTermnt = true;
            break;
        } else if ((*RdoMap_Integer)[RPLKEY.UPD_THREAD_STATE] == NT::THREAD_PAUSE) {
            while (true) {
                if ((*RdoMap_Integer)[RPLKEY.UPD_THREAD_STATE] == NT::THREAD_PAUSE) {
                    QThread::msleep(15);
                    continue;
                } else {
                    break;
                }
            }
        } else {
            QString MatchResult = Iter.next().capturedTexts().last();
            emit st_value(MatchResult);
            emit process(((double)AddCount / (double)range) * 100);
            AddCount++;
            QThread::msleep(15);
        }
    }
    if (AddCount < TotalLenght && !IsTermnt)
    {
        QString LastChar = StickData.mid((SingleStep * range), -1);
        emit st_value(LastChar);
        emit process(((double)AddCount / (double)range) * 100);
        AddCount++;
    }

    emit finish(true);
    st_mutex.unlock();
}


private:
    QMap<QString, qint64> *RdoMap_Integer;
    QMutex st_mutex;
    bool IsTermnt = false;
    KEY_ATTRIBUTE RPLKEY;

 signals:

     void process(int);
     void st_value(QString);
     void finish(bool);

};

#endif



//class ExcelCompare : public QObject, public QRunnable{

//    Q_OBJECT

//public:

//    ExcelCompare(QMap<QString, QList<QString>> &_RdoMap_ListChar_, QMap<QString, QTextDocument*> &_RdoMap_Document_, QMap<QString, QString> &_RdoMap_String_);

//    void run();

//private:
//    QMap<QString, QList<QString>> *RdoMap_ListChar;
//    QMap<QString, QString> *RdoMap_String;
//    QMap<QString, QTextDocument*> *RdoMap_Document;

//};
